<%@ page contentType="text/html; charset=UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<%@ include file="/app/include.jsp"%>
		<link rel="stylesheet" href="${pageContext.request.contextPath}/common/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css" />
		<script type="text/javascript" src="${pageContext.request.contextPath}/common/zTree/js/jquery.ztree.core-3.5.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/common/zTree/js/jquery.ztree.excheck-3.5.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/common/zTree/js/jquery.ztree.exedit-3.5.js"></script>
		<script type="text/javascript">
			var setting = {
				view: {
				   selectedMulti: false
				},
				data: {
					simpleData: {
						enable: true
					}
				},
				callback: {
					onClick:treeClick
					//onCheck: beforeCheck
					
				},
				async: {
					enable: true,
					url:"${pageContext.request.contextPath}/auth/dict/treeData4Dict.do"
				}
				
			};
			//树点击事件
			function treeClick(event, treeId, treeNode){
				var level = treeNode.level;
				var id = treeNode.id;
				var url = "";
				if(level == '0'){
					//设置按钮属性--不可以修改根节点和删除根节点
					return false;
				}else if(level == '1'){//查看字典集下边的字典内容
					$("#selectnodeId").val(treeNode.tId);//讲当前选中节点的tid保存到隐藏域中
					//设置按钮属性--增加删除都可以使用
					url = "${pageContext.request.contextPath}/auth/dict/loadDictDataList.do?codetype=" + id;
				}
				$("#dataInfo").attr("src",url);
			}
			
			//增加
			function addChildNode(){
				$("#selectnodeId").val();
				var fromUrl = "${pageContext.request.contextPath}/app/module/dict/insert-one-dict.jsp";
				var toUrl = "${pageContext.request.contextPath}/auth/dict/addOneDict.do";
				var title = "添加字典集信息";
				Tool.showUpdateDialog(fromUrl,toUrl,title,500,100,refreashTreeNodes);
			}
			
			
			//更新树
			function refreashTreeNodes(){
				var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
				treeObj.reAsyncChildNodes(null, "refresh");
				setTimeout(selectFirstNode,500);
			}
			
			//删除树节点
			function delNode(){
				var selectnodeId = $("#selectnodeId").val();
				$("#selectnodeId").val("");
				var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
				var treeNode = treeObj.getNodeByTId(selectnodeId);
				var level = treeNode.level;
				var id = treeNode.id;
				var params = "";
				var url = "";
				if(level == '0'){//根节点不能删除
					return false;
				}else if(level == '1'){//删除字典集
					$("#selectnodeId").val("");
					url = "${pageContext.request.contextPath}/auth/dict/delOneDict.do?codeytpe=" + id;
					params = {"codetype":id};
				}
				if(confirm("确定要删除选中字典集？")){
					$.ajax({
					url : url,
					type : 'post',
					data : params,
					dataType: 'text',
					cache: false,
					success:function(data){
						alert(data);
						treeObj.removeNode(treeNode);
						selectFirstNode();
					},
					error:function(data){
						Dialog.alert("操作失败！");
					}
				});
				}
			}
			
			//更新树节点
			function updateNode(){
				var selectnodeId = $("#selectnodeId").val();
				var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
				var treeNode = treeObj.getNodeByTId(selectnodeId);
				var level = treeNode.level;
				if(level=='0'){
					return;
				}
				var id = treeNode.id;
				var fromUrl = "${pageContext.request.contextPath}/auth/dict/selectOneDict.do?codeytpe=" + id;
				var toUrl = "${pageContext.request.contextPath}/auth/dict/editOneDict.do";
				var title = "修改字典集信息";
				Tool.showUpdateDialog(fromUrl,toUrl,title,500,100);
			}
			
			//选中节点
			function selectFirstNode(){
				var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
				var nodes = treeObj.getNodes()[0].children;
				var node = nodes[0];
				treeObj.selectNode(node);
				treeClick(null, "treeDemo", node);
			}
			
			$(document).ready(function(){
				$.fn.zTree.init($("#treeDemo"), setting);
				//setTimeout(expendsTree,500);
			});
		</script>
			<style type="text/css">
				.ztree li span.button.icon01_ico_docu{margin-right:2px; background: url(${pageContext.request.contextPath}/common/zTree/css/zTreeStyle/img/diy/2.png) no-repeat scroll 0 0 transparent; vertical-align:top; *vertical-align:middle}
			</style>
	</head>
	<body id="inner-body">
		<dl class="tree">
			<!-- <dt class="seleMenu">
		    	<select style="width:190px;" onchange="changeTree(this)">
		        	<option value="zhuanti">专题管理</option>
		        	<option value="index">标引管理</option>
		        </select>
		    </dt> -->
		    <dd class="toolIcon">
		    	<img src="${pageContext.request.contextPath}/layout/skins/blue/images/icon_add.gif" id="addImgButton" onclick="addChildNode()" title="增加子节点"/>
		        <img src="${pageContext.request.contextPath}/layout/skins/blue/images/icon_delete.gif" id="delImgButton" onclick="delNode()" title="删除当前节点"/>
		        <img src="${pageContext.request.contextPath}/layout/skins/blue/images/icon_edit.gif" id="editImgButton" onclick="updateNode()"/>
		    </dd>
		    <dd class="autoHeight">
		    	<ul id="treeDemo" class="ztree"></ul>
		    </dd>
		</dl>
		<div id="inner-content">
             <iframe id="dataInfo" name="right" frameborder="0" scrolling="auto"></iframe>
		</div>
		<input type="hidden" id="selectnodeId"/><!--不可删除该属性，主要用于动态更新树节点取得当前节点  -->
	</body>
</html>